import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
        isLogin: window.sessionStorage.getItem("token") ? true : false,
        token: "",
        loginUser: {}
  },
    mutations: {
        SET_LOGIN(state, loginUser) {
            state.loginUser = loginUser;
            state.islogin = true;
            state.token = loginUser.token;
            window.sessionStorage.setItem("token", loginUser.token);
        },
        SET_LOGOUT(state) {
            state.loginUser = "",
                state.islogin = false,
                state.token = ""
        }
    },
    actions: {
        login(context, loginUser) {
            context.commit('SET_LOGIN', loginUser);
        },
        logout() {
            context.commit('SET_LOGOUT', loginUser);
        }
    },
  modules: {
  }
})
